<template>
    <div class="user-page" style="background: whitesmoke;height: 700px;">
    <div class="top">
      <img :src="user.avatar" alt="" style="width: 50px;height: 50px; margin-right: 20px;border-radius: 50%;"/>
      <h4>{{user.username}}</h4>
    </div>
    <van-grid clickable :column-num="3"  class="middle">
      <van-grid-item icon="clock-o" text="历史记录" to="/" />
      <van-grid-item icon="bookmark-o" text="我的收藏" to="/collect" />
      <van-grid-item icon="thumb-circle-o" text="我的点赞" to="/like" />
    </van-grid>

    <van-cell-group class="mt20">
      <van-cell title="推荐分享" is-link />
      <van-cell title="意见反馈" is-link />
      <van-cell title="关于我们" is-link />
      <van-cell title="退出登录" is-link @click="exit"/>
    </van-cell-group>
    </div>
</template>
<script>
import {getUser} from '@/api/user'
import {removeToke} from '@/utils/storage'
import { mapState } from 'vuex'
export default{
    name:'user-page',
    data(){
        return{
            user:{}
        }
    },
    async created(){
      const data = await getUser()
      console.log(data)
      //把数据绑定data
      this.user = data.data
    },
    methods:{
        //弹出确认框
        exit(){
            this.$dialog.confirm({
                title:'退出登录',
                message:'是否确认退出登录'           
            }).then(() => {
                    //删除token
                    removeToke()
                    this.$router.push('/logon')
            }).catch(() =>{})//catch用户点击取消登录不会爆红
        }
    }

}
</script>
<style>
*{
    margin: 0;
    padding: 0;
    
}
.top{
    padding: 10px;
    display: flex;
    height: 60px;
    line-height: 60px;
}
.middle{
    margin-top: 10px;
    margin-bottom: 10px;
}
</style>